package winOrDie.graphicsInterface.GameMenu;

import java.util.Vector;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;


public class Composite_Main extends Composite {

	
	private Button button_ShowGames = null;
	public Button getButton_ShowGames() {
		return button_ShowGames;
	}

	public void setButton_ShowGames(Button button_ShowGames) {
		this.button_ShowGames = button_ShowGames;
	}

	private Button button_JoinGame = null;
	private Button button_CreateGame = null;
	private Button button_Options = null;
	
	private Vector<Composite_Main_Listener> listeners = null;
	
	public synchronized void add_Composite_Main_Listener(Composite_Main_Listener listener)
	{
		listeners.add(listener);
	}
	
	public synchronized void remove_Composite_Main_Listener(Composite_Main_Listener listener)
	{
		listeners.remove(listener);
	}
	
	protected void fire_Composite_Main_Event(Composite_Main_Event event)
	{
		for (Composite_Main_Listener listener : listeners) {
			listener.onComposite_Main_Change(event);
		}
	}
	
	public Composite_Main(Composite parent, int style) {
		super(parent, style);
		
		listeners = new Vector<Composite_Main_Listener>();
		initialize();
	}

	private void initialize() {
		setSize(new Point(300, 200));
		setLayout(new GridLayout());
		
		final Composite_Main compositeMain = this;
		
		/**
		 * List Games button
		 */
		GridData gridData_Button_ShowGames = new GridData();
		gridData_Button_ShowGames.horizontalAlignment = org.eclipse.swt.layout.GridData.CENTER;
		button_ShowGames = new Button(this, SWT.NONE);
		button_ShowGames.setText("Mostrar partidas");
		button_ShowGames.setLayoutData(gridData_Button_ShowGames);
		button_ShowGames.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Composite_Main_Event event = new Composite_Main_Event(compositeMain);
				event.setEventType(Composite_Main_Event.Event_Types.LIST_GAMES);
				fire_Composite_Main_Event(event);
			}
		});
		
		
		
		/**
		 * Join Game button
		 */
		GridData gridData_Button_Join_Game = new GridData();
		gridData_Button_Join_Game.horizontalAlignment = org.eclipse.swt.layout.GridData.CENTER;
		button_JoinGame = new Button(this, SWT.NONE);
		button_JoinGame.setText("Unirse a partida");
		button_JoinGame.setLayoutData(gridData_Button_Join_Game);
		button_JoinGame.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Composite_Main_Event event = new Composite_Main_Event(compositeMain);
				event.setEventType(Composite_Main_Event.Event_Types.JOIN_GAME);
				fire_Composite_Main_Event(event);
			}
		});
		
		/**
		 * Create game button
		 */
		GridData gridData_Button_Create_Game = new GridData();
		gridData_Button_Create_Game.horizontalAlignment = org.eclipse.swt.layout.GridData.CENTER;
		gridData_Button_Create_Game.verticalIndent = 10;
		button_CreateGame = new Button(this, SWT.NONE);
		button_CreateGame.setText("Crear partida");
		button_CreateGame.setLayoutData(gridData_Button_Create_Game);
		button_CreateGame.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Composite_Main_Event event = new Composite_Main_Event(compositeMain);
				event.setEventType(Composite_Main_Event.Event_Types.CREATE_GAME);
				fire_Composite_Main_Event(event);
			}
		});
		
		
		/**
		 * Create game button
		 */
		GridData gridData_Button_Options = new GridData();
		gridData_Button_Options.horizontalAlignment = org.eclipse.swt.layout.GridData.CENTER;
		gridData_Button_Options.verticalIndent = 10;
		button_Options = new Button(this, SWT.NONE);
		button_Options.setText("Opciones");
		button_Options.setLayoutData(gridData_Button_Options);
		button_Options.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Composite_Main_Event event = new Composite_Main_Event(compositeMain);
				event.setEventType(Composite_Main_Event.Event_Types.OPTIONS);
				fire_Composite_Main_Event(event);
			}
		});
	}


	
	
}
